<template>
  <div class="login">
    <el-form :model="loginForm" class="login-container">
      <h1>欢迎登录</h1>
      <el-form-item>
        <el-input v-model="loginForm.username" placeholder="请输入账号" type="input"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="loginForm.password" placeholder="请输入密码" type="password"></el-input>
      </el-form-item>
      <el-form-item class="button-container">
        <el-button type="primary" @click="handleLogin">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script setup>
import { reactive, getCurrentInstance } from 'vue'
// 引入获取路由
import { useAllDataStore } from '../stores/index'
import { useRouter } from 'vue-router'
// 储存输入的用户以及密码
const loginForm = reactive({
  username: '',
  password: ''
})
const store = useAllDataStore()
const router = useRouter()
// 获取接口数据
const { proxy } = getCurrentInstance()
// 登录按钮
const handleLogin = async () => {
  const res = await proxy.$api.getMenu(loginForm)
  // console.log(res);
  // 获取菜单更新
  store.updateMenuList(res.menuList)
  // 获取储存token里面的用户，需要做对比
  store.state.token = res.token
  // 动态路由
  store.addMenu(router)
  // 获取成功之后跳转到home页面
  router.push('/home')

}

</script>
<style lang="less" scoped>
.login {
  width: 100%;
  height: 100%;
  background-image: url("../assets/images/background.png");
  background-size: 100%;
  overflow: hidden;
}

.login-container {
  width: 400px;
  background-color: #fff;
  border-radius: 15px;
  border: 1px solid #eaeaea;
  padding: 35px 35px 15px 35px;
  margin: 250px auto;
  box-shadow: 0 0 25px #cacaca;

  h1 {
    font-size: 20px;
    margin-bottom: 20px;
    text-align: center;
  }

  :deep(.el-form-item__content) {
    justify-content: center;
  }
}
</style>